<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/public/header.jsp"%>
<%
	String gd_id = request.getParameter("gd_id") == null ? "" : request.getParameter("gd_id");
	String gd_content_id = request.getParameter("gd_content_id") == null ? "" : request.getParameter("gd_content_id");
%>
<html>
	<head>
	<script type="text/javascript">
		$(function(){
			$('#table').datagrid({
				title:'甲供材料领用情况汇总(绿色背景表示该材料使用量低于管控最小值)',
				url:'<%=contextPath %>/springMVC/gd/getGDBalanceMaterialBefore?type=0&gd_id=<%=gd_id%>&gd_content_id=<%=gd_content_id%>',
				rownumbers:true,
				singleSelect:true,
				fitColumns:true,
				columns:[[
					{title:'预   算',width:600,align:'center',colspan:7},
					{title:'甲供使用情况',width:500,align:'center',colspan:5}
				],[
					{title:'产品名称',field:'name',width:100,align:'center'},
					{title:'规格/型号',field:'format_type',width:100,align:'center'},
					{title:'单位',field:'unit_name',width:50,align:'center'},
					{title:'预算数量',field:'assume_num',width:100,align:'center'},
					{title:'管控精度(%)',field:'control',width:100,align:'center'},
					{title:'最小管控值',field:'min_num',width:100,align:'center',formatter:function(value,row,index){
						var assume_num = parseFloat(row.assume_num);
					    if(assume_num == 0){
					    	return 0;
					    }
			    	    var control = parseFloat(row.control)/100;
			    	    var min_num = Math.round(assume_num*(1-control)*Math.pow(10,2))/Math.pow(10,2);
			    	    return  min_num;
					}},
					{title:'已用合计',field:'already_use',width:100,align:'center'},
					{title:'合计',field:'total',width:100,align:'center',formatter:function(value,row,index){
						row.total = parseFloat(row.use_old_num)+parseFloat(row.customer_num)+parseFloat(row.purchase_num)+parseFloat(row.recovery_num);
						return row.total;
					}},
					{title:'利旧数',field:'use_old_num',width:100,align:'center'},
					{title:'甲供领料',field:'customer_num',width:100,align:'center'},
					{title:'采购数',field:'purchase_num',width:100,align:'center'},
					{title:'回收数',field:'recovery_num',width:100,align:'center'}
				   ]],
			   rowStyler : function(index,row){
				    var assume_num = parseFloat(row.assume_num);
				    var total = parseFloat(row.use_old_num)+parseFloat(row.customer_num)+parseFloat(row.purchase_num)+parseFloat(row.recovery_num);
				    if(assume_num == 0 || total == 0){
				    	return 'background-color:#fff;color:black;';
				    }
		    	    var control = parseFloat(row.control)/100;
		    	    var min_num = Math.round(assume_num*(1-control)*Math.pow(10,2))/Math.pow(10,2);
		    	    var max_num = Math.round(assume_num*(1+control)*Math.pow(10,2))/Math.pow(10,2);
		    	    
					if(parseFloat(row.already_use) < parseFloat(min_num))
					{	
						return 'background-color:#0aa344;color:black;';
					}
					if(parseFloat(max_num) < parseFloat(row.already_use))
					{	
						return 'background-color:#ffee00;color:red;';
					}
					return 'background-color:#fff;color:black;';
				}
			});
		});
		
	</script>
	</head>
	<body>
			<div id="table" ></div>
	</body>
</html>